package com.dgw.config;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @program: spring-boot-web-restfulcrud
 * @description: 配置国际化连接解析
 * @author: Mr.Dai
 * @create: 2019-11-30 17:32
 **/
public class LocaleSetting implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        /**
         * l=('en_US') 取得连接字符串
         * l=('zh_CN')
         */
        String lstr = request.getParameter("l");
        Locale locale = Locale.getDefault();
        if(!StringUtils.isEmpty(lstr)){
            String[] split = lstr.split("_");
            System.out.println(split);
            locale = new Locale("en","US");
        }
        return new Locale("en","US");
    }
    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) { }
}
